package com.baseproject.base.pojo;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;

public class User implements HttpSessionBindingListener {

	private String username;
	private String password;
	


	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public User(String username, String password) {
		super();
		this.username = username;
		this.password = password;
	}

	
	
	@Override
	public void valueBound(HttpSessionBindingEvent event) {
		// TODO Auto-generated method stub
			User user=(User)event.getValue();
			List<String> usernames=OnLinePojo.getUsers();
			usernames.add(this.username);
			event.getSession().setAttribute("usernames", usernames);
			System.out.println("user add" + user.getUsername()+"=========="+user.getPassword()+"======"+usernames.size());
			System.out.println("usernames.size()="+usernames.size());
	}

	@Override
	public void valueUnbound(HttpSessionBindingEvent event) {
		// TODO Auto-generated method stub
		try {
			User user=(User)event.getValue();
			List<String> usernames=OnLinePojo.getUsers();
			System.out.println("user remove" + user.getUsername()+"=========="+user.getPassword()+"======"+usernames.size());
			usernames.remove(this.username);
			System.out.println("usernames.size()="+usernames.size());
			//event.getSession().setAttribute("usernames", usernames);
		} catch (Exception e) {
			// TODO Auto-generated catch block
		
		}

	}
	
	

}
